package p1TopN;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

//筛选出历史温度最高的十条记录
//参数：D:/topninput D:/topnoutput
public class topnDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
//        args=new String[] {"D:/topninput","D:/topnoutput"};

        Configuration conf = new Configuration();
        Job job=Job.getInstance(conf);

        job.setJarByClass(topnDriver.class);

        job.setMapperClass(topnMapper.class);
        job.setReducerClass(topnReducer.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(AverageTempBean.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(AverageTempBean.class);

        FileInputFormat.addInputPath(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job,new Path(args[1]));

        //7.提交作业
        boolean result = job.waitForCompletion(true);//抛出异常直接在外面抛就可以选第一个
        //如果result是true则说明提交成功，返回0，如果是fault则说明提交失败返回1
        System.exit(result ? 0 : 1);
    }
}
